Hi there! This notebook covers the basic ptplot interface for making plots. You'll see how easy it is to generate an interactive, beautiful-looking plot showing player-tracking data, as well as some knobs you can tweak to adjust things just to how you want.

We'll start with some simple imports.

We'll pick a single play to look at, just for demonstration purposes. I've somewhat-randomly chosen this Cleveland Browns reverse + WR pass from the 2018 season, which has player-tracking data available for it from Adam Sonty's ngs_highlights repo (specifically, the file used is located here).

Let's start by making a simple plot that shows player positions at a certain frame. Frames where interesting stuff happens are actually tagged by the event column, so we'll choose the moment of time when the pass occurred:

That's nice, but all the players look the same, which isn't very helpful. The good news is that it's pretty easy to make things clearer. First we'll add a column to the DataFrame to denote which rows contain the ball, then we'll use that column + others to add team and player information:

Much better. In addition to the addition of team colors and player numbers, note that mousing over the markers shows the player's name too. You can also use the Plotly controls on the top right of the chart to do things like zoom in, select players, and save a static image.

in addition to making plots of player positions, ptplot can also generate tracks of player positions over the course of the play. The code in the next cell generates those tracks for the entire play:

Again you'll see similar interactivity as for the player positions plot.

Now, if you want both the positions and player tracks, it's possible to combine these two figures by re-using the figure object that ptplot's plotting functions return:

Lastly, ptplot comes with support for both horizontal and vertical field orientations. Horizontal views tend to be better for computers, which tend towards widescreen displays, while vertical views scroll better on phones.